package com.fbs.service.impl;

import com.aaa.entity.RRolePermission;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fbs.dao.RRolePermissionDao;
import com.fbs.service.RRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class RRolePermissionServiceImpl extends ServiceImpl<RRolePermissionDao, RRolePermission> implements RRolePermissionService {
    @Autowired
    private RRolePermissionDao rRolePermissionDao;
    @Override
    public Result addPermission(String id, List<String> pid) {
        Integer integer = rRolePermissionDao.deleteAllByiD(id);
        List<RRolePermission> list=new ArrayList<>();

        for (String s : pid) {
            RRolePermission rRolePermission = new RRolePermission();
            rRolePermission.setRoleId(id);
            rRolePermission.setPermissionId(s);
            rRolePermission.setIsDeleted("0");
            Date date = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = formatter.format(date);
            rRolePermission.setGmtCreate(dateString);
            int insert = rRolePermissionDao.insert(rRolePermission);
        }
        return new Result(200,"权限分配成功");
    }

}
